package com.xinziruo.crawl.application.crawl.impl;

import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.xinziruo.crawl.application.CrawlEvents;
import com.xinziruo.crawl.domain.crawl.CrawlApiObject;
import com.xinziruo.crawl.domain.crawl.api.CrawlEventFilterChain;
import com.xinziruo.crawl.infrastruture.SpringBeanHolder;
import com.xinziruo.crawl.infrastruture.messaging.event.CrawlEventImpl;

/**
 * 
 * @author loudyn
 * 
 */
public class QuartzCrawlJob extends QuartzJobBean {

	public static final String SCHEDULE_GROUP = "crawl.api.job";
	public static final String CRAWL_API_OBJECT = "crawl.api.object";

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org
	 * .quartz.JobExecutionContext)
	 */
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

		JobDetail job = context.getJobDetail();
		CrawlApiObject api = (CrawlApiObject) job.getJobDataMap().get(CRAWL_API_OBJECT);
		CrawlEventFilterChain fc = SpringBeanHolder.getBean(CrawlEventFilterChain.class);
		CrawlEvents crawlEvents = SpringBeanHolder.getBean(CrawlEvents.class);
		crawlEvents.crawlEventWasCreated(new CrawlEventImpl(api), fc);
	}

}
